/**
 * @file attitude_estimator.h
 * @brief Attitude Estimator for H743-V2 Flight Control System
 * @author Flight Control Team
 * @date 2025-10-31
 */

#ifndef __ATTITUDE_ESTIMATOR_H
#define __ATTITUDE_ESTIMATOR_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

/**
 * @brief Attitude data structure
 */
typedef struct {
    float roll;         // Roll angle (rad)
    float pitch;        // Pitch angle (rad)
    float yaw;          // Yaw angle (rad)
    float roll_rate;    // Roll rate (rad/s)
    float pitch_rate;   // Pitch rate (rad/s)
    float yaw_rate;     // Yaw rate (rad/s)
    uint64_t timestamp;
} Attitude_t;

/**
 * @brief Initialize attitude estimator
 * @return 0 on success, -1 on error
 */
int AttitudeEstimator_Init(void);

/**
 * @brief Update attitude estimate
 * @param accel_x Accelerometer X (m/s^2)
 * @param accel_y Accelerometer Y (m/s^2)
 * @param accel_z Accelerometer Z (m/s^2)
 * @param gyro_x Gyroscope X (rad/s)
 * @param gyro_y Gyroscope Y (rad/s)
 * @param gyro_z Gyroscope Z (rad/s)
 * @param mag_x Magnetometer X (Gauss)
 * @param mag_y Magnetometer Y (Gauss)
 * @param mag_z Magnetometer Z (Gauss)
 * @param dt Time step (s)
 * @return 0 on success, -1 on error
 */
int AttitudeEstimator_Update(float accel_x, float accel_y, float accel_z,
                             float gyro_x, float gyro_y, float gyro_z,
                             float mag_x, float mag_y, float mag_z,
                             float dt);

/**
 * @brief Get current attitude
 * @param attitude Pointer to attitude structure
 * @return 0 on success, -1 on error
 */
int AttitudeEstimator_GetAttitude(Attitude_t *attitude);

#ifdef __cplusplus
}
#endif

#endif /* __ATTITUDE_ESTIMATOR_H */

